﻿using UnityEngine;
using System.Collections;
namespace GameEditor
{
    public class MoveEye2D : MonoBehaviour
    {
        public  Camera EyeCamera;
        public Vector3 move_step;  
        public static MoveEye2D CreateEye(Transform parent,Hashtable cfgTable)
        { 
            GameObject newObj = new GameObject("MoveEye2D");
            MoveEye2D eye2d = newObj.AddComponent<MoveEye2D>();
            newObj.transform.parent = parent;
           
            eye2d.EyeCamera = newObj.AddComponent<Camera>();
            eye2d.EyeCamera.cullingMask = 1;

            eye2d.EyeCamera.fieldOfView = (float)cfgTable[":view"];
            eye2d.EyeCamera.transform.localPosition = UnityHelpler.OArray2Vec3((object[])cfgTable[":start-pos"]);

            eye2d.move_step = UnityHelpler.OArray2Vec3((object[])cfgTable[":move-step"]);
            return eye2d;
        }

        public void Update()
        {
            if (Input.GetKey(KeyCode.W))
            {
                transform.localPosition += new Vector3(0,move_step.y*Time.deltaTime,0);
            }

            if (Input.GetKey(KeyCode.S))
            {
                transform.localPosition += new Vector3(0, -move_step.y*Time.deltaTime, 0);
            }

            if (Input.GetKey(KeyCode.A))
            {
                transform.localPosition += new Vector3(-move_step.x*Time.deltaTime, 0, 0);
            }

            if (Input.GetKey(KeyCode.D))
            {
                transform.localPosition += new Vector3(move_step.x*Time.deltaTime, 0, 0);
            }
            float scroll = Input.GetAxis("Mouse ScrollWheel");
            if (scroll != 0)
            {
                transform.localPosition += new Vector3(0,0, scroll* move_step.z * Time.deltaTime);
            }
        }
    }

   
}